package com.liangxy.zhyl.controller;

import com.liangxy.zhyl.base.PageResponse;
import com.liangxy.zhyl.base.ResponseResult;
import com.liangxy.zhyl.dto.NursingProjectDto;
import com.liangxy.zhyl.service.NursingProjectService;
import com.liangxy.zhyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目的控制器
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询护理项目列表
     */
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>>
    nursingProjectList(@RequestParam(required = false) String name,  // 护理项目名称
                       @RequestParam(required = false) Integer status,  //  状态 ： 0 禁用；1 启用
                       @RequestParam(defaultValue = "10" ) Integer pageSize,  // 每页数量
                       @RequestParam(defaultValue = "1", required = false) Integer pageNum) { // 页码
        PageResponse<NursingProjectVo> pageData = nursingProjectService.getByPage(name, status, pageSize, pageNum);
        return success(pageData);
    }
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.add(nursingProjectDTO);
        return ResponseResult.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVO = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVO);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.update(nursingProjectDTO);
        return ResponseResult.success();
    }
    @GetMapping("/all")
    @ApiOperation("查询所有的护理项目")
    public ResponseResult<NursingProjectVo> getAll() {
        List<NursingProjectVo> nursingProjectVO = nursingProjectService.getAll();
        return ResponseResult.success(nursingProjectVO);
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")
    public ResponseResult updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(@PathVariable("id") Long id) {
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }
}
